/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tkgarment.system.dao;

import com.tkgarment.system.domain.DataFile;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class DataFileDAO extends AbstractDAO implements IDAO<DataFile, Integer>{

    @Override
    public List<DataFile> getAll() throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
     public List<DataFile> getByEmpID(String empId) throws Exception {
        String sql = "select  * from datafile where emp_id = ?";
         if (this.getCon() == null) {
             this.setCon(DAOFactory.creatConnection());
         }
        // System.out.println(sql + empId);
         List<Map<String , Object >> result = this.getCon().queryList(sql, empId);
         List<DataFile> files = new ArrayList<>();
         for (Map<String, Object> map : result) {
             DataFile f = new DataFile();
             f.setFileId(Integer.parseInt(map.get(DataFile.field_file_id).toString()));
             f.setCreateBy(map.get(DataFile.field_create_by).toString());
             f.setCreateOn((Date)map.get(DataFile.field_create_on));
             f.setFileName(map.get(DataFile.field_file_name).toString());
             f.setFileType(map.get(DataFile.field_file_type_name).toString());
             f.setEmpId(map.get(DataFile.field_emp_id).toString());
             files.add(f);
         }
         return files;
    }

    @Override
    public int updateSingle(DataFile t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(DataFile t) throws Exception {
        String sql = "delete  from datafile where file_id = ?";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        return this.getCon().update(sql,t.getFileId());
        
    }

    @Override
    public int insertSingle(DataFile t) throws Exception {
       String sql = "INSERT INTO datafile(" +
            "            file_type_name, file_name, create_by, create_on, emp_id)" +
        "    VALUES (?, ?, ?, current_timestamp ,?)";
       
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        return this.getCon().add(sql, t.getFileType(),t.getFileName(),t.getCreateBy(),t.getEmpId());
        
    }

    @Override
    public DataFile getById(Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
